package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.common.OwnerEditResult;
import com.yh.homestay.pojo.UserOwner;
import com.yh.homestay.service.UserOwnerService;
import com.yh.homestay.utils.QiNiuUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName UserOwnerController
 * @Description 房东Controller
 * @Date 2020/1/13 17:25
 */
@RestController
@Api(description = "房东管理")
@RequestMapping(value = "/owner")
public class UserOwnerController {
    @Autowired
    private UserOwnerService ownerService;

    /**
     * @param ownerName
     * @param page
     * @param limit
     * @Date: 2020/1/13 17:32
     * @Description: 获取房东列表
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @SystemLog(methods = "房东信息列表", module = "房东管理")
    @ApiOperation(value = "获取房东列表", notes = "获取房东信息列表或者模糊查询数据")
    public HomeStayResult selectAll(String ownerName, Integer page, Integer limit) {
        HomeStayResult homeStayResult = ownerService.selectAll(ownerName, page, limit);
        return homeStayResult;
    }


    /**
     * @param userOwner
     * @Date: 2020/1/13 17:32
     * @Description: 添加房东
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @SystemLog(methods = "添加房东", module = "房东管理")
    @ApiOperation(value = "添加房东", notes = "添加房东信息")
    public HomeStayResult addOwner(UserOwner userOwner) {
        userOwner.setOwnerPhoto(QiNiuUtil.qiniu_img_url_pre + userOwner.getOwnerPhoto());
        userOwner.setOwnerIdcardA(QiNiuUtil.qiniu_img_url_pre + userOwner.getOwnerIdcardA());
        userOwner.setOwnerIdcardB(QiNiuUtil.qiniu_img_url_pre + userOwner.getOwnerIdcardB());
        HomeStayResult homeStayResult = ownerService.addOwner(userOwner);
        return homeStayResult;
    }

    /**
     * @param id
     * @Date: 2020/1/13 17:32
     * @Description: 回显房东信息
     * @return: com.yh.homestay.common.OwnerEditResult
     */
    @RequestMapping(value = "/selectOne/{id}",method = RequestMethod.POST)
    @ApiOperation(value = "回显房东信息", notes = "根据id回显房东信息")
    public OwnerEditResult editOwner(@PathVariable Integer id) {
        OwnerEditResult ownerEditResult = ownerService.selectOne(id);
        return ownerEditResult;
    }

    /**
     * @param ownerId
     * @param ownerName
     * @param ownerPhone
     * @param ownerPhoto
     * @param ownerIdcardA
     * @param ownerIdcardB
     * @param ownerRoomIds
     * @Date: 2020/1/13 17:33
     * @Description: 修改房东信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @SystemLog(methods = "修改房东信息", module = "房东管理")
    @ApiOperation(value = "修改房东信息", notes = "修改房东信息")
    public HomeStayResult editMember(Integer ownerId, String ownerName, String ownerPhone, String ownerPhoto, String ownerIdcardA, String ownerIdcardB, String ownerRoomIds) {
        HomeStayResult update = ownerService.update(ownerId, ownerName, ownerPhone, ownerPhoto, ownerIdcardA, ownerIdcardB, ownerRoomIds);
        return update;
    }

    /**
     * @param ownerId
     * @Date: 2020/1/13 17:33
     * @Description: 删除房东
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.POST)
    @SystemLog(methods = "删除房东", module = "房东管理")
    @ApiOperation(value = "删除房东", notes = "根据删除房东")
    public HomeStayResult deleteById(@PathVariable(value = "id") Integer ownerId) {
        HomeStayResult delete = ownerService.delete(ownerId);
        return delete;
    }

    /**
     * @param ids
     * @Date: 2020/1/13 17:33
     * @Description: 批量删除房东
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.POST)
    @SystemLog(methods = "删除多个房东", module = "房东管理")
    @ApiOperation(value = "批量删除房东", notes = "根据ids批量删除房东")
    public HomeStayResult delectAll(@RequestParam List<Integer> ids) {
        HomeStayResult homeStayResult = ownerService.delectAll(ids);
        return homeStayResult;
    }


}
